package com.djnt.catering.sales_promotion;

import android.app.Activity;
import android.content.ContentValues;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.EditText;

import com.djnt.catering.R;
import com.djnt.catering.Settings;
import com.djnt.catering.database.HotNews;

public class ViewReadOnly extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.sales_promotion_user_view);
		EditText username = (EditText) this.findViewById(R.id.username);
		SharedPreferences sp = PreferenceManager
				.getDefaultSharedPreferences(this);
		String str1 = sp.getString(Settings.Persist.USERNAME, null);
		username.setText(sp.getString(Settings.Persist.NICKNAME, str1));
	}

	public void onSubmit(View view) {
		Uri uri = saveToDraft();
		this.finish();
	}

	public void onSave(View view) {
		Uri uri = saveToDraft();
		this.finish();
	}

	private Uri saveToDraft() {
		// TODO Auto-generated method stub
		ContentValues cv = new ContentValues();
		EditText username = (EditText) this.findViewById(R.id.username);
		EditText phone = (EditText) this.findViewById(R.id.phone);
		EditText email = (EditText) this.findViewById(R.id.email);
		EditText caption = (EditText) this.findViewById(R.id.caption);
		EditText body = (EditText) this.findViewById(R.id.body);
		long date = System.currentTimeMillis();
		cv.put(HotNews.NAME, username.getText().toString());
		cv.put(HotNews.PHONE, phone.getText().toString());
		cv.put(HotNews.EMAIL, email.getText().toString());
		cv.put(HotNews.CAPTION, caption.getText().toString());
		cv.put(HotNews.BODY, body.getText().toString());
		cv.put(HotNews.DATE, date);
		cv.put(HotNews.STATUS, HotNews.Status.Draft);
		return this.getContentResolver().insert(HotNews.CONTENT_URI, cv);
	}
}
